package com.jy.rhin.infra.repo.zhibiao.assembler;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jy.rhin.zhibiao.model.dto.PingTaiDYCSDto;
import com.jy.rhin.zhibiao.model.po.PingTaiDYCSPo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yuyue
 * @date 2024/3/22
 */
public class PingTaiDYCSAssembler {

    private PingTaiDYCSAssembler() {

    }

    public static Page<PingTaiDYCSDto> poPageToDtoPage(Page<PingTaiDYCSPo> poPage) {
        if (poPage == null) {
            return null;
        }

        Page<PingTaiDYCSDto> page = new Page<PingTaiDYCSDto>();

        page.setPages(poPage.getPages());
        page.setRecords(pingTaiDYCSPoListToPingTaiDYCSDtoList(poPage.getRecords()));
        page.setTotal(poPage.getTotal());
        page.setSize(poPage.getSize());
        page.setCurrent(poPage.getCurrent());
        page.setSearchCount(poPage.isSearchCount());
        page.setOptimizeCountSql(poPage.isOptimizeCountSql());
        page.setHitCount(poPage.isHitCount());
        List<OrderItem> list1 = poPage.getOrders();
        if (list1 != null) {
            page.setOrders(new ArrayList<>(list1));
        }
        page.setCountId(poPage.getCountId());
        page.setMaxLimit(poPage.getMaxLimit());

        return page;
    }

    protected static PingTaiDYCSDto pingTaiDYCSPoToPingTaiDYCSDto(PingTaiDYCSPo pingTaiDYCSPo) {
        if (pingTaiDYCSPo == null) {
            return null;
        }

        PingTaiDYCSDto pingTaiDYCSDto = new PingTaiDYCSDto();

        pingTaiDYCSDto.setId(pingTaiDYCSPo.getId());
        pingTaiDYCSDto.setTongJiRQ(pingTaiDYCSPo.getTongJiRQ());
        pingTaiDYCSDto.setZhiBiaoMC(pingTaiDYCSPo.getZhiBiaoMC());
        pingTaiDYCSDto.setZhiBiaoDM(pingTaiDYCSPo.getZhiBiaoDM());
        pingTaiDYCSDto.setDiaoYongCS(pingTaiDYCSPo.getDiaoYongCS());
        pingTaiDYCSDto.setChuangJianSJ(pingTaiDYCSPo.getChuangJianSJ());

        return pingTaiDYCSDto;
    }

    protected static List<PingTaiDYCSDto> pingTaiDYCSPoListToPingTaiDYCSDtoList(List<PingTaiDYCSPo> list) {
        if (list == null) {
            return null;
        }

        List<PingTaiDYCSDto> list1 = new ArrayList<>(list.size());
        for (PingTaiDYCSPo pingTaiDYCSPo : list) {
            list1.add(pingTaiDYCSPoToPingTaiDYCSDto(pingTaiDYCSPo));
        }

        return list1;
    }
}
